package routes

import (
	v1 "ginblog/api/v1"
	 "ginblog/middleware"
	"ginblog/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.New()
	r.Use(middleware.Logger())
	r.Use(gin.Recovery())

	auth := r.Group("api/v1")
	auth.Use(middleware.Cors())
	//auth.Use(middleware.JwtToken())
	{
		//根据username查询user
		auth.GET("get/user/:username", v1.SelectByName)
		//根据id删除user
		auth.DELETE("get/user/:id", v1.DeleteUser)
		//编辑user
		auth.POST("edit/user/:id", v1.EditUser)

		//添加category
		auth.POST("add/category", v1.AddCategory)

		//根据id删除category
		auth.DELETE("delete/category/:id", v1.DeleteCategoryById)
		//编辑category
		auth.POST("edit/category/:id", v1.EditCategoryById)

		//新增article
		auth.POST("add/article", v1.Addrticle)
		//编辑article
		auth.POST("edit/article/:id", v1.EditArticle)
		//删除article
		auth.DELETE("delete/article/:id", v1.DeleteArticle)

	}
	router := r.Group("api/v1")
	{
		//新增user
		router.POST("add/user", v1.AddUser)
		//查询所有users
		router.GET("get/users", v1.GetUsers)
		//查询所有的categorys
		router.GET("get/categorys", v1.GetCategorys)
		//根据id查询category
		router.GET("get/category/:id", v1.GetCategoryById)
		//查询所有文章
		router.GET("select/articles", v1.GetArticles)
		//查询单个文章
		router.GET("select/article/:id", v1.GetArticle)
		//查询分类下的文章
		router.GET("select/catart", v1.GetCategoryArticles)
		//登陆
		router.POST("login", v1.Login)
		//上传文件
		router.POST("upload", v1.UpLoad)
		_ = r.Run(utils.HttpPort)
	}
}
